//自定义运算
import java.util.Scanner;
public class calculate {
    public static void main(String[] args) {
        Scanner reader = new Scanner(System.in);
        System.out.print("请输入第一个数: ");
        double num1 = reader.nextDouble();
        System.out.print("请输入运算符 (+, -, *, /): ");
        char symbol = reader.next().charAt(0);              //已自学String与charAt
        System.out.print("请输入第二个数: ");
        double num2 = reader.nextDouble();

        double result = 0;

        switch (symbol) {
            case '+':
                result = num1 + num2;
                break;
            case '-':
                result = num1 - num2;
                break;
            case '*':
                result = num1 * num2;
                break;
            case '/':
                if (num2 != 0) {
                    result = num1 / num2;
                }
                else {
                    System.out.println("除数不能为零！");
                    return;
                }
                break;
            default:
                System.out.println("无效的运算符");
                return;
        }

        System.out.println("计算结果: " + result);
    }
}
